package com.example.listener;

import com.example.annotation.DeclareQueue;
import com.example.annotation.ShardRabbitListener;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
@DeclareQueue(prefixQueueName = "aaaaa_BOND_EXECUTION_COMMAND", QueueSize = "1")
public class ConsumerListener {

    @ShardRabbitListener(id = "IndQuotationQueue#0", queueNamePrefix = "aaaaa_BOND_EXECUTION_COMMAND",
            shardSize = "1",
            maxConsumeAmount = "1",
            concurrency = "2")
    public void receiveMessage(@Payload String message, org.springframework.amqp.core.Message amqpMessage, Channel channel) throws IOException {
        long deliveryTag = amqpMessage.getMessageProperties().getDeliveryTag();
        try {
//            Thread.sleep(10);
            System.out.println(message);
            channel.basicAck(deliveryTag,false);
        } catch (Exception e) {
            channel.basicNack(deliveryTag,false,true);
        }
    }
}
